import pandas as pd
from answer1.Boxes import BoxItem
import cv2
from answer1.vision_utils import ImgBoxes

boxes = [BoxItem(_) for _ in pd.read_json("answer1/boxes.json")['boxes']]
# 要求1：打印 'box_b' 的 'rectangle' 字段
[print(i.name, '-rectangle:', i.meta_data['rectangle']) for i in boxes if i.name == 'box_b']
for b in boxes:
    if b.name == 'box_b':
        boxb = b
img1 = cv2.imread("answer1/images/1.jpg")
img2 = cv2.imread("answer1/images/2.jpg")
imgbox1 = ImgBoxes(boxb, img1)
imgbox2 = ImgBoxes(boxb, img2)


# 将图片2覆盖到图片1上面
imgbox1 += imgbox2
# 保存结果
visualize_size = (img1.shape[1]//4, img1.shape[0]//4)
cv2.imshow('window', cv2.resize(img1, visualize_size)); cv2.waitKey(0)
cv2.imshow('window', cv2.resize(img2, visualize_size)); cv2.waitKey(0)
cv2.imshow('window', cv2.resize(imgbox1.img, visualize_size))
cv2.waitKey(0)
cv2.imwrite('answer1/images/res.jpg', imgbox1.img)

